#include "QueryPlanNode.h"

SelectFileNode::SelectFileNode(DBFile* file, char *name, int outPipeId, CNF* cnf,
		Record* literal, Pipe *outPipe) : QueryPlanNode(selectfile),
		file(file), outPipeId(outPipeId), cnf(cnf), literal(literal), outPipe(outPipe) {
	strcpy(filename, name);
}

void SelectFileNode::Print(){
	cout<<"********\n";
	cout<<"Select File\n";
	cout<<"Input File: "<<filename<<endl;
	cout<<"Output pipe ID "<<outPipeId<<endl;
	cout<<"Select File CNF:\n";
	cnf->Print();
	cout<<"********\n";
}

void SelectFileNode::Execute(){
	sf.Use_n_Pages(RUN_LENGTH);
	sf.Run(*file, *outPipe, *cnf, *literal);
}

void SelectFileNode::Wait(){
	sf.WaitUntilDone();
}

void SelectFileNode::Clean(){
    file->Close();
    delete file, outPipe, out_pipe;
}
